import { merge } from '@/utils/core'
import { ElMessage, MessageHandler, MessageOptions } from 'element-plus'
export declare interface HElMessage {
    // [key: string]: (message: string, options?: MessageOptions) => MessageHandler
    success:(message: string, options?: MessageOptions) => MessageHandler
    info:(message: string, options?: MessageOptions) => MessageHandler
    warning:(message: string, options?: MessageOptions) => MessageHandler
    error:(message: string, options?: MessageOptions) => MessageHandler
}

export const useElMessage = (): HElMessage => {
    const defaultOptions = {
        duration: 2500,  // 持续时间
        offset: 20, // 偏移量
        showClose: false, // 显示关闭按钮
    }
    return {
        success: (message, options = {}) => {
            options['message'] = message;
            return ElMessage.success(merge(options, defaultOptions))
        },
        info: (message, options = {}) => {
            options['message'] = message;
            return ElMessage.info(merge(options, defaultOptions))
        },
        warning: (message, options = {}) => {
            options['message'] = message;
            return ElMessage.warning(merge(options, defaultOptions))
        },
        error: (message, options = {}) => {
            options['message'] = message;
            return ElMessage.error(merge(options, defaultOptions))
        },
    }
}